package com.yrihr.wisdom.controller;

import com.yrihr.wisdom.common.ResponseBody;
import com.yrihr.wisdom.common.ResponseCode;
import com.yrihr.wisdom.entity.News;
import com.yrihr.wisdom.service.NewsSercice;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName : WebController
 * @Description : 主页controller
 * @Author : wind
 * @Date: 2020-11-27 10:05
 * @Version 1.0
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "知识服务中心主页")
@Slf4j
public class WebController {

    private final NewsSercice newsSercice;
    /**
     * @return
     */
    @ApiOperation("主页新闻轮播")
    @RequestMapping(value = "/api/news/carousel", method = RequestMethod.POST)
    public ResponseBody carousel() {
        List<News> news = newsSercice.selectTodayNews();
        if (news != null) {
            if (news.size() > 0) {
                log.info("主页轮播模块，查询到当天的新闻信息");
                return ResponseBody.success(ResponseCode.SELECT_TODAY_NEWS_SUCCESS, news);
            } else {
                log.warn("主页轮播模块，没有查询到当天的新闻");
                return ResponseBody.error(ResponseCode.SELECT_TODAY_NEWS_ERROR, null);
            }
        } else {
            log.error("主页轮播模块，查询当天的新闻信息失败");
            return ResponseBody.error(ResponseCode.SELECT_TODAY_NEWS_ERROR, null);
        }

    }
}
